1 Imports System.Data.SqlClient
2 Imports System.IO
3
4 Public Class frmQuotation
5 Dim st2 As String
6
7 Sub Reset()
8 txtCID.Text = ""
9 txtRemarks.Text = ""
10 txtCustomerName.Text = ""
11 txtAmount.Text = ""
12 txtSellingPrice.Text = ""
13 txtCustomerID.Text = ""
14 txtDiscountAmount.Text = ""
15 txtDiscountPer.Text = ""
16 txtQuotationNo.Text = ""
17 txtProductCode.Text = ""
18 txtProductName.Text = ""
19 txtQty.Text = ""
20 txtSellingPrice.Text = ""
21 txtTotalAmount.Text = ""
22 txtTotalQty.Text = ""
23 txtVAT.Text = ""
24 txtVATAmount.Text = ""
25 txtGrandTotal.Text = ""
26 dtpQuotationDate.Text = Today
27 btnDelete.Enabled = False
28 btnUpdate.Enabled = False
29 btnSave.Enabled = True
30 btnRemove.Enabled = False
31 btnAdd.Enabled = True
32 btnPrint.Enabled = False
33 txtContactNo.Text = ""
34 txtCustomerType.Text = ""
35 auto()
36 lblSet.Text = "Allowed"
37 DataGridView1.Rows.Clear()
38 Clear()
39 End Sub
40 Private Function GenerateID() As String
41 con = New SqlConnection(cs)
42 Dim value As String = "0000"
43 Try
44 ' Fetch the latest ID from the database
45 con.Open()
46 cmd = New SqlCommand("SELECT TOP 1 Q_ID FROM Quotation order BY Q_ID DESC", con)
47 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
48 If rdr.HasRows Then
49 rdr.Read()
50 value = rdr.Item("Q_ID")
51 End If
52 rdr.Close()
53 ' Increase the ID by 1
54 value += 1
55 ' Because incrementing a string with an integer removes 0's
56 ' we need to replace them. If necessary.
57 If value <= 9 Then 'Value is between 0 and 10
58 value = "000" & value
59 ElseIf value <= 99 Then 'Value is between 9 and 100
60 value = "00" & value
61 ElseIf value <= 999 Then 'Value is between 999 and 1000
62 value = "0" & value
63 End If
64 Catch ex As Exception
65 ' If an error occurs, check the connection state and close it if necessary.
66 If con.State = ConnectionState.Open Then
67 con.Close()
68 End If
69 value = "0000"
70 End Try
71 Return value
72 End Function
73 Sub auto()
74 Try
75 txtID.Text = GenerateID()
76 txtQuotationNo.Text = "Q-" + GenerateID()
77 Catch ex As Exception
78 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
79 End Try
80 End Sub
81
82
83 Private Sub btnClose_Click(sender As System.Object, e As System.EventArgs) Handles btnClose.Click
84 Me.Close()
85 End Sub
86
87 Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles btnSelectionInv.Click
88 frmProductRecord.lblSet.Text = "Quotation"
89 frmProductRecord.Reset()
90 frmProductRecord.ShowDialog()
91 End Sub
92 Sub Compute()
93 Dim num1, num2, num3, num4, num5 As Double
94 num1 = CDbl(Val(txtQty.Text) * Val(txtSellingPrice.Text))
95 num1 = Math.Round(num1, 2)
96 txtAmount.Text = num1
97 num2 = CDbl((Val(txtAmount.Text) * Val(txtDiscountPer.Text)) / 100)
98 num2 = Math.Round(num2, 2)
99 txtDiscountAmount.Text = num2
100 num3 = Val(txtAmount.Text) - Val(txtDiscountAmount.Text)
101 num4 = CDbl((Val(txtVAT.Text) * Val(num3)) / 100)
102 num4 = Math.Round(num4, 2)
103 txtVATAmount.Text = num4
104 num5 = CDbl(Val(txtAmount.Text) + Val(txtVATAmount.Text) - Val(txtDiscountAmount.Text))
105 num5 = Math.Round(num5, 2)
106 txtTotalAmount.Text = num5
107 End Sub
108
109 Private Sub txtQty_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtQty.TextChanged
110 Compute()
111 End Sub
112
113 Private Sub txtQty_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtQty.KeyPress
114 If (e.KeyChar < Chr(48) Or e.KeyChar > Chr(57)) And e.KeyChar <> Chr(8) Then
115 e.Handled = True
116 End If
117 End Sub
118 Public Function GrandTotal() As Double
119 Dim sum As Double = 0
120 Try
121 For Each r As DataGridViewRow In Me.DataGridView1.Rows
122 sum = sum + r.Cells(9).Value
123 Next
124 Catch ex As Exception
125 MsgBox(ex.Message)
126 End Try
127 Return sum
128 End Function
129 Sub Print()
130 Try
131 If txtCustomerType.Text <> "Non Regular" Then
132 Cursor = Cursors.WaitCursor
133 Timer1.Enabled = True
134 Dim rpt As New rptQuotation 'The report you created.
135 Dim myConnection As SqlConnection
136 Dim MyCommand, MyCommand1 As New SqlCommand()
137 Dim myDA, myDA1 As New SqlDataAdapter()
138 Dim myDS As New DataSet 'The DataSet you created.
139 myConnection = New SqlConnection(cs)
140 MyCommand.Connection = myConnection
141 MyCommand1.Connection = myConnection
142 MyCommand.CommandText = "SELECT Customer.ID, Customer.Name, Customer.Gender, Customer.Address, Customer.City, Customer.State, Customer.ZipCode, Customer.ContactNo, Customer.EmailID,Customer.Photo, Quotation.Q_ID, Quotation.QuotationNo, Quotation.Date, Quotation.GrandTotal, Quotation_Join.QJ_ID, Quotation_Join.QuotationID,Quotation_Join.ProductID, Quotation_Join.Cost, Quotation_Join.Qty, Quotation_Join.Amount, Quotation_Join.DiscountPer, Quotation_Join.Discount, Quotation_Join.VATPer, Quotation_Join.VAT,Quotation_Join.TotalAmount, Product.PID, Product.ProductCode, Product.ProductName FROM Customer INNER JOIN Quotation ON Customer.ID = Quotation.CustomerID INNER JOIN Quotation_Join ON Quotation.Q_ID = Quotation_Join.QuotationID INNER JOIN Product ON Quotation_Join.ProductID = Product.PID where QuotationNo=@d1"
143 MyCommand.Parameters.AddWithValue("@d1", txtQuotationNo.Text)
144 MyCommand1.CommandText = "SELECT * from Company"
145 MyCommand.CommandType = CommandType.Text
146 MyCommand1.CommandType = CommandType.Text
147 myDA.SelectCommand = MyCommand
148 myDA1.SelectCommand = MyCommand1
149 myDA.Fill(myDS, "Quotation")
150 myDA.Fill(myDS, "Quotation_Join")
151 myDA.Fill(myDS, "Customer")
152 myDA.Fill(myDS, "Product")
153 myDA1.Fill(myDS, "Company")
154 rpt.SetDataSource(myDS)
155 rpt.SetParameterValue("p1", txtCustomerID.Text)
156 rpt.SetParameterValue("p2", Today)
157 frmReport.CrystalReportViewer1.ReportSource = rpt
158 frmReport.ShowDialog()
159 End If
160 If txtCustomerType.Text = "Non Regular" Then
161 Cursor = Cursors.WaitCursor
162 Timer1.Enabled = True
163 Dim rpt As New rptQuotation1 'The report you created.
164 Dim myConnection As SqlConnection
165 Dim MyCommand, MyCommand1 As New SqlCommand()
166 Dim myDA, myDA1 As New SqlDataAdapter()
167 Dim myDS As New DataSet 'The DataSet you created.
168 myConnection = New SqlConnection(cs)
169 MyCommand.Connection = myConnection
170 MyCommand1.Connection = myConnection
171 MyCommand.CommandText = "SELECT Customer.ID, Customer.Name, Customer.Gender, Customer.Address, Customer.City, Customer.State, Customer.ZipCode, Customer.ContactNo, Customer.EmailID,Customer.Photo, Quotation.Q_ID, Quotation.QuotationNo, Quotation.Date, Quotation.GrandTotal, Quotation_Join.QJ_ID, Quotation_Join.QuotationID,Quotation_Join.ProductID, Quotation_Join.Cost, Quotation_Join.Qty, Quotation_Join.Amount, Quotation_Join.DiscountPer, Quotation_Join.Discount, Quotation_Join.VATPer, Quotation_Join.VAT,Quotation_Join.TotalAmount, Product.PID, Product.ProductCode, Product.ProductName FROM Customer INNER JOIN Quotation ON Customer.ID = Quotation.CustomerID INNER JOIN Quotation_Join ON Quotation.Q_ID = Quotation_Join.QuotationID INNER JOIN Product ON Quotation_Join.ProductID = Product.PID where QuotationNo=@d1"
172 MyCommand.Parameters.AddWithValue("@d1", txtQuotationNo.Text)
173 MyCommand1.CommandText = "SELECT * from Company"
174 MyCommand.CommandType = CommandType.Text
175 MyCommand1.CommandType = CommandType.Text
176 myDA.SelectCommand = MyCommand
177 myDA1.SelectCommand = MyCommand1
178 myDA.Fill(myDS, "Quotation")
179 myDA.Fill(myDS, "Quotation_Join")
180 myDA.Fill(myDS, "Customer")
181 myDA.Fill(myDS, "Product")
182 myDA1.Fill(myDS, "Company")
183 rpt.SetDataSource(myDS)
184 rpt.SetParameterValue("p1", txtCustomerID.Text)
185 rpt.SetParameterValue("p2", Today)
186 frmReport.CrystalReportViewer1.ReportSource = rpt
187 frmReport.ShowDialog()
188 End If
189 Catch ex As Exception
190 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
191 End Try
192
193 End Sub
194 Private Sub frmBilling_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
195
196 End Sub
197
198 Private Sub btnAdd_Click(sender As System.Object, e As System.EventArgs) Handles btnAdd.Click
199 Try
200 If txtProductCode.Text = "" Then
201 MessageBox.Show("Please retrieve product code", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
202 txtProductCode.Focus()
203 Exit Sub
204 End If
205 If txtQty.Text = "" Then
206 MessageBox.Show("Please enter quantity", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
207 txtQty.Focus()
208 Exit Sub
209 End If
210 If txtQty.Text = 0 Then
211 MessageBox.Show("Quantity can not be zero", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
212 txtQty.Focus()
213 Exit Sub
214 End If
215 If DataGridView1.Rows.Count = 0 Then
216 DataGridView1.Rows.Add(txtProductCode.Text, txtProductName.Text, txtSellingPrice.Text, txtQty.Text, txtAmount.Text, txtDiscountPer.Text, txtDiscountAmount.Text, txtVAT.Text, txtVATAmount.Text, txtTotalAmount.Text, txtProductID.Text)
217 Dim k As Double = 0
218 k = GrandTotal()
219 k = Math.Round(k, 2)
220 txtGrandTotal.Text = k
221 Clear()
222 Exit Sub
223 End If
224 For Each r As DataGridViewRow In Me.DataGridView1.Rows
225 If r.Cells(0).Value = txtProductCode.Text Then
226 r.Cells(0).Value = txtProductCode.Text
227 r.Cells(1).Value = txtProductName.Text
228 r.Cells(2).Value = txtSellingPrice.Text
229 r.Cells(3).Value = Val(r.Cells(3).Value) + Val(txtQty.Text)
230 r.Cells(4).Value = Val(r.Cells(4).Value) + Val(txtAmount.Text)
231 r.Cells(5).Value = Val(txtDiscountPer.Text)
232 r.Cells(6).Value = Val(r.Cells(6).Value) + Val(txtDiscountAmount.Text)
233 r.Cells(7).Value = Val(txtVAT.Text)
234 r.Cells(8).Value = Val(r.Cells(8).Value) + Val(txtVATAmount.Text)
235 r.Cells(9).Value = Val(r.Cells(9).Value) + Val(txtTotalAmount.Text)
236 r.Cells(10).Value = txtProductID.Text
237 Dim i As Double = 0
238 i = GrandTotal()
239 i = Math.Round(i, 2)
240 txtGrandTotal.Text = i
241 Clear()
242 Exit Sub
243 End If
244 Next
245 DataGridView1.Rows.Add(txtProductCode.Text, txtProductName.Text, txtSellingPrice.Text, txtQty.Text, txtAmount.Text, txtDiscountPer.Text, txtDiscountAmount.Text, txtVAT.Text, txtVATAmount.Text, txtTotalAmount.Text, txtProductID.Text)
246 Dim j As Double = 0
247 j = GrandTotal()
248 j = Math.Round(j, 2)
249 txtGrandTotal.Text = j
250 Clear()
251 Catch ex As Exception
252 MsgBox(ex.Message)
253 End Try
254 End Sub
255 Sub Clear()
256 txtProductCode.Text = ""
257 txtProductName.Text = ""
258 txtSellingPrice.Text = ""
259 txtQty.Text = ""
260 txtAmount.Text = ""
261 txtDiscountPer.Text = ""
262 txtDiscountAmount.Text = ""
263 txtVAT.Text = ""
264 txtVATAmount.Text = ""
265 txtTotalAmount.Text = ""
266 btnAdd.Enabled = True
267 btnRemove.Enabled = False
268 btnListUpdate.Enabled = False
269 End Sub
270
271 Private Sub btnRemove_Click(sender As System.Object, e As System.EventArgs) Handles btnRemove.Click
272 Try
273 For Each row As DataGridViewRow In DataGridView1.SelectedRows
274 DataGridView1.Rows.Remove(row)
275 Next
276 Dim k As Double = 0
277 k = GrandTotal()
278 k = Math.Round(k, 2)
279 txtGrandTotal.Text = k
280 Compute()
281 Clear()
282 Catch ex As Exception
283 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
284 End Try
285 End Sub
286
287 Private Sub DataGridView1_MouseClick(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseClick
288
289 If (Me.DataGridView1.Rows.Count > 0) Then
290 If lblSet.Text = "Not Allowed" Then
291 btnRemove.Enabled = False
292 btnListUpdate.Enabled = False
293 Else
294 btnRemove.Enabled = True
295 btnListUpdate.Enabled = True
296 End If
297 Me.btnAdd.Enabled = False
298 Dim row As DataGridViewRow = Me.DataGridView1.SelectedRows.Item(0)
299 Me.txtProductCode.Text = (row.Cells.Item(0).Value)
300 Me.txtProductName.Text = (row.Cells.Item(1).Value)
301 Me.txtSellingPrice.Text = (row.Cells.Item(2).Value)
302 Me.txtQty.Text = (row.Cells.Item(3).Value)
303 Me.txtAmount.Text = (row.Cells.Item(4).Value)
304 Me.txtDiscountPer.Text = (row.Cells.Item(5).Value)
305 Me.txtDiscountAmount.Text = (row.Cells.Item(6).Value)
306 Me.txtVAT.Text = (row.Cells.Item(7).Value)
307 Me.txtVATAmount.Text = (row.Cells.Item(8).Value)
308 Me.txtTotalAmount.Text = (row.Cells.Item(9).Value)
309 Me.txtProductID.Text = (row.Cells.Item(10).Value)
310 End If
311 End Sub
312
313 Private Sub DataGridView1_RowPostPaint(sender As Object, e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles DataGridView1.RowPostPaint
314 Dim strRowNumber As String = (e.RowIndex + 1).ToString()
315 Dim size As SizeF = e.Graphics.MeasureString(strRowNumber, Me.Font)
316 If DataGridView1.RowHeadersWidth < Convert.ToInt32((size.Width + 20)) Then
317 DataGridView1.RowHeadersWidth = Convert.ToInt32((size.Width + 20))
318 End If
319 Dim b As Brush = SystemBrushes.ControlText
320 e.Graphics.DrawString(strRowNumber, Me.Font, b, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))
321
322 End Sub
323
324 Private Sub btnDelete_Click(sender As System.Object, e As System.EventArgs) Handles btnDelete.Click
325 Try
326 If MessageBox.Show("Do you really want to delete this record?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.Yes Then
327 DeleteRecord()
328 End If
329 Catch ex As Exception
330 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
331 End Try
332 End Sub
333 Private Sub DeleteRecord()
334
335 Try
336 Dim RowsAffected As Integer = 0
337 con = New SqlConnection(cs)
338 con.Open()
339 Dim cq As String = "delete from Quotation where Q_ID=@d1"
340 cmd = New SqlCommand(cq)
341 cmd.Parameters.AddWithValue("@d1", txtID.Text)
342 cmd.Connection = con
343 RowsAffected = cmd.ExecuteNonQuery()
344 If RowsAffected > 0 Then
345 Dim st As String = "deleted the invoice no. '" & txtQuotationNo.Text & "'"
346 LogFunc(lblUser.Text, st)
347 MessageBox.Show("Successfully deleted", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
348 Reset()
349 Else
350 MessageBox.Show("No Record found", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Information)
351 Reset()
352 End If
353 If con.State = ConnectionState.Open Then
354 con.Close()
355
356 End If
357 Catch ex As Exception
358 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
359 End Try
360 End Sub
361 Private Function GenerateID1() As String
362 con = New SqlConnection(cs)
363 Dim value As String = "0000"
364 Try
365 ' Fetch the latest ID from the database
366 con.Open()
367 cmd = New SqlCommand("SELECT TOP 1 ID FROM Customer ORDER BY ID DESC", con)
368 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
369 If rdr.HasRows Then
370 rdr.Read()
371 value = rdr.Item("ID")
372 End If
373 rdr.Close()
374 ' Increase the ID by 1
375 value += 1
376 ' Because incrementing a string with an integer removes 0's
377 ' we need to replace them. If necessary.
378 If value <= 9 Then 'Value is between 0 and 10
379 value = "000" & value
380 ElseIf value <= 99 Then 'Value is between 9 and 100
381 value = "00" & value
382 ElseIf value <= 999 Then 'Value is between 999 and 1000
383 value = "0" & value
384 End If
385 Catch ex As Exception
386 ' If an error occurs, check the connection state and close it if necessary.
387 If con.State = ConnectionState.Open Then
388 con.Close()
389 End If
390 value = "0000"
391 End Try
392 Return value
393 End Function
394 Sub auto1()
395 Try
396 txtCID.Text = GenerateID1()
397 txtCustomerID.Text = "C-" + GenerateID1()
398 Catch ex As Exception
399 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
400 End Try
401 End Sub
402 Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click
403 If Len(Trim(txtCustomerName.Text)) = 0 Then
404 MessageBox.Show("Please retrieve customer details", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
405 Exit Sub
406 End If
407 If DataGridView1.Rows.Count = 0 Then
408 MessageBox.Show("sorry no product added to cart", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
409 Exit Sub
410 End If
411 Try
412 con = New SqlConnection(cs)
413 con.Open()
414 Dim ctn1 As String = "select * from Company"
415 cmd = New SqlCommand(ctn1)
416 cmd.Connection = con
417 rdr = cmd.ExecuteReader()
418
419 If Not rdr.Read() Then
420 MessageBox.Show("Add company profile first in master entry", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
421 If (rdr IsNot Nothing) Then
422 rdr.Close()
423 End If
424 Return
425 End If
426 If txtCustomerName.ReadOnly = False Then
427 auto1()
428 con = New SqlConnection(cs)
429 con.Open()
430 Dim cbn As String = "insert into Customer(ID, CustomerID, [Name], Gender, Address, City, ContactNo, EmailID,Remarks,State,ZipCode,Photo,CustomerType) Values (@d1,@d2,@d3,@d4,@d5,@d6,@d7,@d8,@d9,@d10,@d11,@d12,'Non Regular')"
431 cmd = New SqlCommand(cbn)
432 cmd.Parameters.AddWithValue("@d1", txtCID.Text)
433 cmd.Parameters.AddWithValue("@d2", txtCustomerID.Text)
434 cmd.Parameters.AddWithValue("@d3", txtCustomerName.Text)
435 cmd.Parameters.AddWithValue("@d4", "")
436 cmd.Parameters.AddWithValue("@d5", "")
437 cmd.Parameters.AddWithValue("@d6", "")
438 cmd.Parameters.AddWithValue("@d7", txtContactNo.Text)
439 cmd.Parameters.AddWithValue("@d8", "")
440 cmd.Parameters.AddWithValue("@d9", "")
441 cmd.Parameters.AddWithValue("@d10", "")
442 cmd.Parameters.AddWithValue("@d11", "")
443 cmd.Connection = con
444 Dim ms As New MemoryStream()
445 Dim bmpImage As New Bitmap(My.Resources.photo)
446 bmpImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
447 Dim data As Byte() = ms.GetBuffer()
448 Dim p As New SqlParameter("@d12", SqlDbType.Image)
449 p.Value = data
450 cmd.Parameters.Add(p)
451 cmd.ExecuteNonQuery()
452 con.Close()
453 txtCustomerType.Text = "Non Regular"
454 End If
455 con = New SqlConnection(cs)
456 con.Open()
457 Dim cb As String = "insert into Quotation(Q_ID, QuotationNo, Date, CustomerID, GrandTotal, Remarks) Values (@d1,@d2,@d3,@d4,@d5,@d6)"
458 cmd = New SqlCommand(cb)
459 cmd.Parameters.AddWithValue("@d1", txtID.Text)
460 cmd.Parameters.AddWithValue("@d2", txtQuotationNo.Text)
461 cmd.Parameters.AddWithValue("@d3", dtpQuotationDate.Value.Date)
462 cmd.Parameters.AddWithValue("@d4", txtCID.Text)
463 cmd.Parameters.AddWithValue("@d5", txtGrandTotal.Text)
464 cmd.Parameters.AddWithValue("@d6", txtRemarks.Text)
465 cmd.Connection = con
466 cmd.ExecuteReader()
467 con.Close()
468 con = New SqlConnection(cs)
469 con.Open()
470 Dim cb1 As String = "insert into Quotation_Join(QuotationID, Cost, Qty,Amount, DiscountPer, Discount, VATPer, VAT, TotalAmount,ProductID) VALUES (" & txtID.Text & " ,@d4,@d5,@d6,@d7,@d8,@d9,@d10,@d11,@d12)"
471 cmd = New SqlCommand(cb1)
472 cmd.Connection = con
473 ' Prepare command for repeated execution
474 cmd.Prepare()
475 ' Data to be inserted
476 For Each row As DataGridViewRow In DataGridView1.Rows
477 If Not row.IsNewRow Then
478 cmd.Parameters.AddWithValue("@d4", row.Cells(2).Value)
479 cmd.Parameters.AddWithValue("@d5", row.Cells(3).Value)
480 cmd.Parameters.AddWithValue("@d6", row.Cells(4).Value)
481 cmd.Parameters.AddWithValue("@d7", row.Cells(5).Value)
482 cmd.Parameters.AddWithValue("@d8", row.Cells(6).Value)
483 cmd.Parameters.AddWithValue("@d9", row.Cells(7).Value)
484 cmd.Parameters.AddWithValue("@d10", row.Cells(8).Value)
485 cmd.Parameters.AddWithValue("@d11", row.Cells(9).Value)
486 cmd.Parameters.AddWithValue("@d12", row.Cells(10).Value)
487 cmd.ExecuteNonQuery()
488 cmd.Parameters.Clear()
489 End If
490 Next
491 con.Close()
492 Dim st As String = "added the new quotation having quotation no. '" & txtQuotationNo.Text & "'"
493 LogFunc(lblUser.Text, st)
494 btnSave.Enabled = False
495 If CheckForInternetConnection() = True Then
496 con = New SqlConnection(cs)
497 con.Open()
498 Dim ctn As String = "select RTRIM(APIURL) from SMSSetting where IsDefault='Yes' and IsEnabled='Yes'"
499 cmd = New SqlCommand(ctn)
500 cmd.Connection = con
501 rdr = cmd.ExecuteReader()
502 If rdr.Read() Then
503 st2 = rdr.GetValue(0)
504 Dim st3 As String = "Hello, " & txtCustomerName.Text & " you have successfully applied for quotation having quotation no. " & txtQuotationNo.Text & ""
505 SMSFunc(txtContactNo.Text, st3, st2)
506 If (rdr IsNot Nothing) Then
507 rdr.Close()
508 End If
509 End If
510 End If
511 con.Close()
512 RefreshRecords()
513 MessageBox.Show("Successfully saved", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
514 Print()
515 Catch ex As Exception
516 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
517 End Try
518 End Sub
519
520 Private Sub btnUpdate_Click(sender As System.Object, e As System.EventArgs) Handles btnUpdate.Click
521 If Len(Trim(txtCustomerName.Text)) = 0 Then
522 MessageBox.Show("Please retrieve customer details", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
523 Exit Sub
524 End If
525 If DataGridView1.Rows.Count = 0 Then
526 MessageBox.Show("sorry no product added to cart", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
527 Exit Sub
528 End If
529 Try
530 con = New SqlConnection(cs)
531 con.Open()
532 Dim cb As String = "Update Quotation set QuotationNo=@d2, Date=@d3, CustomerID=@d4, GrandTotal=@d5, Remarks=@d6 where Q_ID=@d1"
533 cmd = New SqlCommand(cb)
534 cmd.Parameters.AddWithValue("@d1", txtID.Text)
535 cmd.Parameters.AddWithValue("@d2", txtQuotationNo.Text)
536 cmd.Parameters.AddWithValue("@d3", dtpQuotationDate.Value.Date)
537 cmd.Parameters.AddWithValue("@d4", txtCID.Text)
538 cmd.Parameters.AddWithValue("@d5", txtGrandTotal.Text)
539 cmd.Parameters.AddWithValue("@d6", txtRemarks.Text)
540 cmd.Connection = con
541 cmd.ExecuteReader()
542 con.Close()
543 Dim st As String = "updated the quotation having invoice no. '" & txtQuotationNo.Text & "'"
544 LogFunc(lblUser.Text, st)
545 btnUpdate.Enabled = False
546 MessageBox.Show("Successfully updated", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
547 Catch ex As Exception
548 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
549 End Try
550 End Sub
551
552 Private Sub btnGetData_Click(sender As System.Object, e As System.EventArgs) Handles btnGetData.Click
553 frmQuotationRecord.Reset()
554 frmQuotationRecord.ShowDialog()
555 End Sub
556
557 Private Sub btnNew_Click(sender As System.Object, e As System.EventArgs) Handles btnNew.Click
558 Reset()
559 End Sub
560
561
562 Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
563 Cursor = Cursors.Default
564 Timer1.Enabled = False
565 End Sub
566
567 Private Sub btnPrint_Click(sender As System.Object, e As System.EventArgs) Handles btnPrint.Click
568 Print()
569 End Sub
570
571 Private Sub btnListReset_Click(sender As System.Object, e As System.EventArgs) Handles btnListReset.Click
572 Clear()
573 End Sub
574
575 Private Sub btnListUpdate_Click(sender As System.Object, e As System.EventArgs) Handles btnListUpdate.Click
576 Try
577 If txtProductCode.Text = "" Then
578 MessageBox.Show("Please retrieve product code", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
579 txtProductCode.Focus()
580 Exit Sub
581 End If
582 If txtQty.Text = "" Then
583 MessageBox.Show("Please enter quantity", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
584 txtQty.Focus()
585 Exit Sub
586 End If
587 If txtQty.Text = 0 Then
588 MessageBox.Show("Quantity can not be zero", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
589 txtQty.Focus()
590 Exit Sub
591 End If
592
593 For Each row As DataGridViewRow In DataGridView1.SelectedRows
594 DataGridView1.Rows.Remove(row)
595 Next
596 DataGridView1.Rows.Add(txtProductCode.Text, txtProductName.Text, txtSellingPrice.Text, txtQty.Text, txtAmount.Text, txtDiscountPer.Text, txtDiscountAmount.Text, txtVAT.Text, txtVATAmount.Text, txtTotalAmount.Text, txtProductID.Text)
597 Dim k As Double = 0
598 k = GrandTotal()
599 k = Math.Round(k, 2)
600 txtGrandTotal.Text = k
601 Clear()
602 Catch ex As Exception
603 MsgBox(ex.Message)
604 End Try
605 End Sub
606
607 Private Sub btnSelect_Click_1(sender As System.Object, e As System.EventArgs) Handles btnSelect.Click
608 frmCustomerRecord2.lblSet.Text = "Quotation"
609 frmCustomerRecord2.lblUser.Text = lblUser.Text
610 frmCustomerRecord2.Reset()
611 frmCustomerRecord2.ShowDialog()
612 End Sub
613 End Class